<template>
  <view style="opacity: 0">
    <view class="matching-view-wrapper">
      <view class="matching-view-box">
        <view class="location-info">
          <view class="info-box">
            <view
              class="name-box"
              :data="JSON.stringify(data)"
              onclick="gotoAutonavi(event)"
            >
              <view class="location-name" v-if="data.matchingId">{{
                data.matchingName || '--'
              }}</view>
              <view class="location-name" v-else>{{ data.name || '--' }}</view>
              <img
                class="location-icon"
                src="/industry/static/map/marker_arrow.png"
                mode="aspectFit"
              />
            </view>
            <span class="location-address">{{ data.matchingAddr || data.address || '--' }}</span>
          </view>
          <view class="map-link-box" :data="JSON.stringify(data)"
              onclick="gotoAutonavi(event)">
            <img class="map-icon" :src="`/industry/static/map/poi_${data.iconType}.png`" mode="aspectFit" />
            <span class="map-link">{{ poiJson[data.iconType] || '--' }}</span>
          </view>
        </view>
      </view>
      <view class="triangle"></view>
      <img
        style="width: 42px; height: 46px; pointer-events: auto;opacity: 0;"
        onclick="matchingViewImghandleClick()"
        :src="`/industry/static/map/poi_${data.iconType}.png`"
        mode="aspectFit"
      />
      <view
        style="height: 2px; width: 50px; background-color: transparent"
      ></view>
    </view>
  </view>
</template>

<script>
import { gotoAutonaive } from './../../utils/index'
export default {
  name: 'MatchingView',
  props: {
    data: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      poiJson:{
        '4':'人才住房',
        '3':'人才驿站',
        '2':'市场化租赁住房',
        '1':'优质居住空间',
        '150501':'地铁口',
        '150500':'地铁口',
        '150700':'公交站',
        '120000':'商圈',
        '060101':'超市',
        '090100':'医院',
        '141200':'学校',
        '160100':'银行',
        '100000':'酒店',
        '110101':'公园',
        '5':'创享驿站',
        '6':'党群中心',
        '7':'综合服务基地',
        '151000':'口岸'
      }
    }
  },
  mounted() {
    window.matchingViewImghandleClick = this.matchingViewImghandleClick
    window.gotoAutonavi = this.gotoAutonavi
  },
  methods: {
    matchingViewImghandleClick() {
      this.$emit('click')
    },
    // 在微信小程序web-view中打开高德地图导航
    gotoAutonavi(event) {
      const json = event.currentTarget.getAttribute('data')
      const data = JSON.parse(json)
      // 从组件props中获取位置信息
      const name = data.matchingName || data.name || '未知位置'
      const address = data.address
      const lng = data.lng || data.longitude || 0
      const lat = data.lat || data.latitude || 0
      gotoAutonaive(lng,lat,name,address)
      //  window.location.href = `https://uri.amap.com/marker?position=${lng},${lat}&name=${encodeURIComponent(
      //       name
      //     )}`
    },
  }
}
</script>

<style scoped lang="scss">
.matching-view-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.matching-view-box {
  display: flex;
  align-items: center;
  padding: 20rpx 30rpx;
  background-color: #ffffff;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
  position: relative;
}

.triangle {
  width: 0;
  height: 0;
  border-left: 16rpx solid transparent;
  border-right: 16rpx solid transparent;
  border-top: 16rpx solid #ffffff;
  box-shadow: 0 -4rpx 8rpx rgba(0, 0, 0, 0.05);
}

.location-info {
  flex: 1;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.info-box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
}
.name-box {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-bottom: 16rpx;
   pointer-events: auto;
}
.location-name {
  font-size: 32rpx;
  line-height: 35rpx;
  font-weight: bold;
  color: #222222;
  max-width: 400rpx;
  overflow: hidden; /* 隐藏溢出的内容 */
  text-overflow: ellipsis; /* 显示省略号 */
  white-space: nowrap; /* 防止文本换行 */
}

.location-address {
  font-size: 28rpx;
  line-height: 30rpx;
  color: #666666;
  margin-top: 10rpx;
  max-width: 430rpx;
  overflow: hidden; /* 隐藏溢出的内容 */
  text-overflow: ellipsis; /* 显示省略号 */
  white-space: nowrap; /* 防止文本换行 */
}

.map-link {
  font-size: 28rpx;
  color: #222222;
  margin-top: 10rpx;
}

.location-icon {
  margin-left: 20rpx;
}

.location-icon {
  width: 30rpx;
  height: 30rpx;
}
.map-icon {
  height: 60rpx;
}
.map-link-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-left: 40rpx;
  margin-bottom: 10rpx;
   pointer-events: auto;
}
.matching-img {
  height: 80rpx;
  width: auto;
}
</style>
